package com.rould.controller;


import com.rould.entity.User;
import com.rould.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Rould
 */
@RestController
@RequestMapping("users")
public class UserAction {

    private final UserService userService;

    public UserAction(UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(value = "one", method = RequestMethod.GET)
    public User one(@RequestParam String id) {
        return userService.getById(id);
    }

    @RequestMapping(value = "all", method = RequestMethod.GET)
    public List<User> all() {
        return userService.list();
    }

    @RequestMapping(value = "save", method = RequestMethod.POST)
    public String save(@RequestBody User user) {
        userService.save(user);
        return "新增成功";
    }

    @RequestMapping(value = "modify", method = RequestMethod.PUT)
    public String modify(@RequestBody User user) {
        userService.updateById(user);
        return "修改成功";
    }

    @RequestMapping(value = "remove", method = RequestMethod.DELETE)
    public String remove(@RequestParam String id) {
        userService.removeById(id);
        return "删除成功";
    }
}
